import de.medieninf.ads.*;

/**Main-Klasse zur Konvertierung von PGM, Integer oder Strings in
 * Binärstrings.
 * 
 * @author Björn Klemm, Gerd Ohlweiler, Anna Macjiewska
 *
 * 
 */

public class Aufg1 {
	
	public static void main(String args[]) {

		if(args.length != 3)	
			errorMsg();
		
		else{
			
			BitString bs;
			String sourcefile = args[0];
			String cmd = args[1];
			String targetfile = args[2];
			
			if(cmd.equals("i2b")){
				bs = new BitString(ADSTool.readIntArray(sourcefile));
				ADSTool.saveStringArray(targetfile,bs.getBinaryString());
			}
			else if(cmd.equals("s2b")){
				bs = new BitString(ADSTool.readStringArray(sourcefile));
				ADSTool.saveStringArray(targetfile,bs.getBinaryString());
			}
			else if(cmd.equals("p2b")){
				bs = new BitString(ADSTool.readPGM(sourcefile));
				ADSTool.saveStringArray(targetfile, bs.getBinaryString());
			}
			else if(cmd.equals("b2i")){
				bs = new BitString(ADSTool.readStringArray(sourcefile));
				ADSTool.saveIntArray(targetfile, bs.getIntegerArray());
			}
			else if(cmd.equals("b2s")){
				bs = new BitString(ADSTool.readStringArray(sourcefile));
				ADSTool.saveStringArray(targetfile, bs.getString());
			}
			else if(cmd.equals("b2p")){
				bs = new BitString( ADSTool.readStringArray(sourcefile));
				ADSTool.savePGM(targetfile, bs.getIntegerArray());
			} 
			else{
				errorMsg();
			}
			System.out.println("Saved as: "+targetfile);
		}
	
	}
	/**
	 * Methode zur Hilfedarstellung wie das Programm genutzt wird
	 */
	private static void errorMsg() {
		System.out.println("Usage:   sourcefile [option] targetfile");
		System.out.println();
		System.out.println("Options:                              ");
		System.out.println("         [i2p] Integerfield to Bitstring");
		System.out.println("         [s2b] Stringfield to Bitstring");
		System.out.println("         [p2b] Pgmfile to Bitstring");
		System.out.println("         [b2i] Bitstring to Integer");
		System.out.println("         [b2s] Bitstring to String");
		System.out.println("         [b2p] Bitstring to Pgmfile");
		
	}

}
